// 本地储存封装
//1.储存
export const setStrage = (key, value) => {
  if (typeof value === "object") {
    //转化成json
    value = JSON.stringify(value);
  }
  //直接储存value为{}[] 自动转换 toString
  window.localStorage.setItem(key, value);
};
// 2.获取
export const getStorage = (key) => {
  let str = window.localStorage.getItem(key);
  //字符串转化
  try {
    str = JSON.parse(str);
  } catch (error) {}
  return str;
};
// 3.删除
export const removeStorage = (key) => {
  window.localStorage.removeItem(key);
};
